/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.web.attach;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unis.common.ui.jqGrid.GridUIMapper;
import com.unis.common.util.WebUtil;
import com.unis.model.BaseModel;
import com.unis.model.attach.AttachLink;
import com.unis.service.attach.AttachLinkService;

/**
 * @author Alucard (email:357375084@qq.com)
 * @since 2013-03-11
 */
@Controller
@RequestMapping("/attachlink")
public class AttachLinkController {

    private AttachLinkService attachlinkService;

    /****************************************
     * Insert a instace of AttachLink
     ****************************************/
    @RequestMapping("/insert")
    @ResponseBody
    public Object insertAttachLink(@RequestBody AttachLink attachlink) throws Exception {
        attachlink.setStatmentId("AttachLink.insert");
        String status = "failure";
        attachlinkService.insert(attachlink);
        status = "success";
        return status;
    }

    /****************************************
     * Update a instace of AttachLink
     ****************************************/
    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody AttachLink attachlink) throws Exception {
        attachlink.setStatmentId("AttachLink.update");
        String status = "failure";
        attachlinkService.update(attachlink);
        status = "success";
        return status;
    }

    /****************************************
     * Delete a instace of AttachLink
     ****************************************/
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody AttachLink attachlink) throws Exception {
        attachlink.setStatmentId("AttachLink.delete");
        String status = "failure";
        attachlinkService.batchDelete(attachlink);
        status = "success";
        return status;
    }

    /****************************************
     * Query instaces of AttachLink
     ****************************************/
    @RequestMapping("/queryAsList")
    @ResponseBody
    public Object queryAsList(HttpServletRequest request) throws Exception {
        Map<String, Object> paramMap = WebUtil.getParamsMapFromRequest(request);
        AttachLink attachlink = new AttachLink();
        attachlink.setStatmentId("AttachLink.queryAsList");
        BeanUtils.populate(attachlink, paramMap);
        Map<String, Object> pageMap = GridUIMapper.process(paramMap);
        BeanUtils.populate(attachlink, pageMap);
        List<BaseModel> attachlinkList = attachlinkService.queryAsList(attachlink);
        Map<String, Object> renderMap = GridUIMapper.render(attachlink, attachlinkList);
        return renderMap;
    }

    /****************************************
     * Query a instaces of AttachLink
     ****************************************/
    @RequestMapping("/queryAsObject")
    @ResponseBody
    public BaseModel queryAsObject(@RequestBody AttachLink attachlink) throws Exception {
        attachlink.setStatmentId("AttachLink.queryAsObject");
        return attachlinkService.queryAsObject(attachlink);
    }

    @RequestMapping("/page")
    public String forword() {
        return "attach/attachlinkList";
    }

    @Resource
    public void setAttachLinkService(AttachLinkService attachlinkService) {
        this.attachlinkService = attachlinkService;
    }
}
